package com.aeoj.clientmanagement.domain.problemrecord.vo;

import com.aeoj.clientmanagement.domain.problemrecord.ProblemRecord;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Date;

/**
 * 刷题记录表
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ProblemRecordVO {
    /**
     * 主键ID
     */
    private Long id;

    /**
     * 题目ID
     */
    private Long problemId;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 房间ID
     */
    private Long roomId;

    /**
     * 题目状态：ACCEPTED, WRONG_ANSWER等
     */
    private String status;

    /**
     * 执行用时
     */
    private String time;

    /**
     * 消耗内存
     */
    private String memory;

    /**
     * 测试用例通过数
     */
    private Integer passedCount;

    /**
     * 测试用例总数
     */
    private Integer totalCount;

    /**
     * 用户代码
     */
    private String code;

    /**
     * 代码语言
     */
    private String language;

    /**
     * 用户备注
     */
    private String remark;

    /**
     * 代码执行消息
     */
    private String message;

    /**
     * 创建时间
     */
    private Date createTime;

    public static ProblemRecordVO toProblemRecordVO(ProblemRecord record) {
        if (record == null) {
            return null;
        }
        return ProblemRecordVO.builder()
                .id(record.getId())
                .problemId(record.getProblemId())
                .userId(record.getUserId())
                .roomId(record.getRoomId())
                .status(record.getStatus())
                .time(record.getTime())
                .memory(record.getMemory())
                .passedCount(record.getPassedCount())
                .totalCount(record.getTotalCount())
                .code(record.getCode())
                .language(record.getLanguage())
                .remark(record.getRemark())
                .message(record.getMessage())
                .createTime(record.getCreateTime())
                .build();
    }

    public ProblemRecord toProblemRecord() {
        return ProblemRecord.builder()
                .id(this.getId())
                .problemId(this.getProblemId())
                .userId(this.getUserId())
                .roomId(this.getRoomId())
                .status(this.getStatus())
                .time(this.getTime())
                .memory(this.getMemory())
                .passedCount(this.getPassedCount())
                .totalCount(this.getTotalCount())
                .code(this.getCode())
                .language(this.getLanguage())
                .remark(this.getRemark())
                .message(this.getMessage())
                .createTime(this.getCreateTime())
                .build();
    }
}